
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 07/31/2012 18:33:34
-- Generated from EDMX file: C:\Users\Clark Nu\documents\visual studio 2010\Projects\CNWebBase\CNWebBase\CNWebBase.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [CNWebBase];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_UserOrganization_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserOrganization] DROP CONSTRAINT [FK_UserOrganization_User];
GO
IF OBJECT_ID(N'[dbo].[FK_UserOrganization_Organization]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserOrganization] DROP CONSTRAINT [FK_UserOrganization_Organization];
GO
IF OBJECT_ID(N'[dbo].[FK_UserPosition_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserPosition] DROP CONSTRAINT [FK_UserPosition_User];
GO
IF OBJECT_ID(N'[dbo].[FK_UserPosition_Position]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserPosition] DROP CONSTRAINT [FK_UserPosition_Position];
GO
IF OBJECT_ID(N'[dbo].[FK_UserRole_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserRole] DROP CONSTRAINT [FK_UserRole_User];
GO
IF OBJECT_ID(N'[dbo].[FK_UserRole_Role]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserRole] DROP CONSTRAINT [FK_UserRole_Role];
GO
IF OBJECT_ID(N'[dbo].[FK_PositionRole_Position]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PositionRole] DROP CONSTRAINT [FK_PositionRole_Position];
GO
IF OBJECT_ID(N'[dbo].[FK_PositionRole_Role]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PositionRole] DROP CONSTRAINT [FK_PositionRole_Role];
GO
IF OBJECT_ID(N'[dbo].[FK_RoleFeatureEntry]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[FeatureEntry] DROP CONSTRAINT [FK_RoleFeatureEntry];
GO
IF OBJECT_ID(N'[dbo].[FK_RoleResourceEntrySelect_Role]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RoleResourceEntrySelect] DROP CONSTRAINT [FK_RoleResourceEntrySelect_Role];
GO
IF OBJECT_ID(N'[dbo].[FK_RoleResourceEntrySelect_ResourceEntry]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RoleResourceEntrySelect] DROP CONSTRAINT [FK_RoleResourceEntrySelect_ResourceEntry];
GO
IF OBJECT_ID(N'[dbo].[FK_RoleResourceEntryAlter_Role]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RoleResourceEntryAlter] DROP CONSTRAINT [FK_RoleResourceEntryAlter_Role];
GO
IF OBJECT_ID(N'[dbo].[FK_RoleResourceEntryAlter_ResourceEntry]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RoleResourceEntryAlter] DROP CONSTRAINT [FK_RoleResourceEntryAlter_ResourceEntry];
GO
IF OBJECT_ID(N'[dbo].[FK_RoleResourceEntryDelete_Role]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RoleResourceEntryDelete] DROP CONSTRAINT [FK_RoleResourceEntryDelete_Role];
GO
IF OBJECT_ID(N'[dbo].[FK_RoleResourceEntryDelete_ResourceEntry]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RoleResourceEntryDelete] DROP CONSTRAINT [FK_RoleResourceEntryDelete_ResourceEntry];
GO
IF OBJECT_ID(N'[dbo].[FK_RoleResourceEntryAdd_Role]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RoleResourceEntryAdd] DROP CONSTRAINT [FK_RoleResourceEntryAdd_Role];
GO
IF OBJECT_ID(N'[dbo].[FK_RoleResourceEntryAdd_ResourceEntry]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RoleResourceEntryAdd] DROP CONSTRAINT [FK_RoleResourceEntryAdd_ResourceEntry];
GO
IF OBJECT_ID(N'[dbo].[FK_OrganizationOrganizationType_Organization]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrganizationOrganizationType] DROP CONSTRAINT [FK_OrganizationOrganizationType_Organization];
GO
IF OBJECT_ID(N'[dbo].[FK_OrganizationOrganizationType_OrganizationType]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrganizationOrganizationType] DROP CONSTRAINT [FK_OrganizationOrganizationType_OrganizationType];
GO
IF OBJECT_ID(N'[dbo].[FK_RoleRoleType]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Role] DROP CONSTRAINT [FK_RoleRoleType];
GO
IF OBJECT_ID(N'[dbo].[FK_FeatureEntryFeatureType]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[FeatureEntry] DROP CONSTRAINT [FK_FeatureEntryFeatureType];
GO
IF OBJECT_ID(N'[dbo].[FK_FeatureEntryL10nLanguage_FeatureEntryL10n]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[FeatureEntryL10nLanguage] DROP CONSTRAINT [FK_FeatureEntryL10nLanguage_FeatureEntryL10n];
GO
IF OBJECT_ID(N'[dbo].[FK_FeatureEntryL10nLanguage_Language]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[FeatureEntryL10nLanguage] DROP CONSTRAINT [FK_FeatureEntryL10nLanguage_Language];
GO
IF OBJECT_ID(N'[dbo].[FK_FeatureEntryFeatureEntryL10n]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[FeatureEntryL10n] DROP CONSTRAINT [FK_FeatureEntryFeatureEntryL10n];
GO
IF OBJECT_ID(N'[dbo].[FK_UserLanguage]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[User] DROP CONSTRAINT [FK_UserLanguage];
GO
IF OBJECT_ID(N'[dbo].[FK_OrganizationTree]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Organization] DROP CONSTRAINT [FK_OrganizationTree];
GO
IF OBJECT_ID(N'[dbo].[FK_FeatureEntryTree]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[FeatureEntry] DROP CONSTRAINT [FK_FeatureEntryTree];
GO
IF OBJECT_ID(N'[dbo].[FK_PositionOrganization]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Position] DROP CONSTRAINT [FK_PositionOrganization];
GO
IF OBJECT_ID(N'[dbo].[FK_OrganizationTypeTree]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrganizationType] DROP CONSTRAINT [FK_OrganizationTypeTree];
GO
IF OBJECT_ID(N'[dbo].[FK_LabelL10nLanguage]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[LabelL10n] DROP CONSTRAINT [FK_LabelL10nLanguage];
GO
IF OBJECT_ID(N'[dbo].[FK_WorkFlowInstanceWorkFlowInstanceNode]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[WorkFlowInstanceNode] DROP CONSTRAINT [FK_WorkFlowInstanceWorkFlowInstanceNode];
GO
IF OBJECT_ID(N'[dbo].[FK_WorkFlowTemplateNodeWorkFlowInstanceNode]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[WorkFlowInstanceNode] DROP CONSTRAINT [FK_WorkFlowTemplateNodeWorkFlowInstanceNode];
GO
IF OBJECT_ID(N'[dbo].[FK_WorkFlowTemplateWorkFlowTemplateNode]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[WorkFlowTemplateNode] DROP CONSTRAINT [FK_WorkFlowTemplateWorkFlowTemplateNode];
GO
IF OBJECT_ID(N'[dbo].[FK_WorkFlowTemplateWorkFlowInstance]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[WorkFlowInstance] DROP CONSTRAINT [FK_WorkFlowTemplateWorkFlowInstance];
GO
IF OBJECT_ID(N'[dbo].[FK_WorkFlowTemplateNodeWorkFlowTemplateNodeDirector]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[WorkFlowTemplateNodeDirector] DROP CONSTRAINT [FK_WorkFlowTemplateNodeWorkFlowTemplateNodeDirector];
GO
IF OBJECT_ID(N'[dbo].[FK_WorkFlowTemplateNodeWorkFlowTemplateNodeDirector1]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[WorkFlowTemplateNode] DROP CONSTRAINT [FK_WorkFlowTemplateNodeWorkFlowTemplateNodeDirector1];
GO
IF OBJECT_ID(N'[dbo].[FK_WorkFlowTemplateNodeRole_WorkFlowTemplateNode]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[WorkFlowTemplateNodeRole] DROP CONSTRAINT [FK_WorkFlowTemplateNodeRole_WorkFlowTemplateNode];
GO
IF OBJECT_ID(N'[dbo].[FK_WorkFlowTemplateNodeRole_Role]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[WorkFlowTemplateNodeRole] DROP CONSTRAINT [FK_WorkFlowTemplateNodeRole_Role];
GO
IF OBJECT_ID(N'[dbo].[FK_WorkFlowInstanceNodeUser_WorkFlowInstanceNode]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[WorkFlowInstanceNodeUser] DROP CONSTRAINT [FK_WorkFlowInstanceNodeUser_WorkFlowInstanceNode];
GO
IF OBJECT_ID(N'[dbo].[FK_WorkFlowInstanceNodeUser_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[WorkFlowInstanceNodeUser] DROP CONSTRAINT [FK_WorkFlowInstanceNodeUser_User];
GO
IF OBJECT_ID(N'[dbo].[FK_WorkFlowInstanceNodeOrganization_WorkFlowInstanceNode]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[WorkFlowInstanceNodeOrganization] DROP CONSTRAINT [FK_WorkFlowInstanceNodeOrganization_WorkFlowInstanceNode];
GO
IF OBJECT_ID(N'[dbo].[FK_WorkFlowInstanceNodeOrganization_Organization]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[WorkFlowInstanceNodeOrganization] DROP CONSTRAINT [FK_WorkFlowInstanceNodeOrganization_Organization];
GO
IF OBJECT_ID(N'[dbo].[FK_WorkFlowInstanceActionWorkFlowInstanceNode]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[WorkFlowInstanceAction] DROP CONSTRAINT [FK_WorkFlowInstanceActionWorkFlowInstanceNode];
GO
IF OBJECT_ID(N'[dbo].[FK_WorkFlowInstanceActionUser_WorkFlowInstanceAction]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[WorkFlowInstanceActionUser] DROP CONSTRAINT [FK_WorkFlowInstanceActionUser_WorkFlowInstanceAction];
GO
IF OBJECT_ID(N'[dbo].[FK_WorkFlowInstanceActionUser_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[WorkFlowInstanceActionUser] DROP CONSTRAINT [FK_WorkFlowInstanceActionUser_User];
GO
IF OBJECT_ID(N'[dbo].[FK_WorkFlowInstanceActionWorkFlowTemplateNodeDirector]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[WorkFlowInstanceAction] DROP CONSTRAINT [FK_WorkFlowInstanceActionWorkFlowTemplateNodeDirector];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Organization]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Organization];
GO
IF OBJECT_ID(N'[dbo].[User]', 'U') IS NOT NULL
    DROP TABLE [dbo].[User];
GO
IF OBJECT_ID(N'[dbo].[Role]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Role];
GO
IF OBJECT_ID(N'[dbo].[Position]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Position];
GO
IF OBJECT_ID(N'[dbo].[FeatureEntry]', 'U') IS NOT NULL
    DROP TABLE [dbo].[FeatureEntry];
GO
IF OBJECT_ID(N'[dbo].[ResourceEntry]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ResourceEntry];
GO
IF OBJECT_ID(N'[dbo].[OrganizationType]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OrganizationType];
GO
IF OBJECT_ID(N'[dbo].[RoleType]', 'U') IS NOT NULL
    DROP TABLE [dbo].[RoleType];
GO
IF OBJECT_ID(N'[dbo].[FeatureType]', 'U') IS NOT NULL
    DROP TABLE [dbo].[FeatureType];
GO
IF OBJECT_ID(N'[dbo].[FeatureEntryL10n]', 'U') IS NOT NULL
    DROP TABLE [dbo].[FeatureEntryL10n];
GO
IF OBJECT_ID(N'[dbo].[Language]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Language];
GO
IF OBJECT_ID(N'[dbo].[LabelL10n]', 'U') IS NOT NULL
    DROP TABLE [dbo].[LabelL10n];
GO
IF OBJECT_ID(N'[dbo].[WorkFlowTemplateNode]', 'U') IS NOT NULL
    DROP TABLE [dbo].[WorkFlowTemplateNode];
GO
IF OBJECT_ID(N'[dbo].[WorkFlowTemplate]', 'U') IS NOT NULL
    DROP TABLE [dbo].[WorkFlowTemplate];
GO
IF OBJECT_ID(N'[dbo].[WorkFlowInstance]', 'U') IS NOT NULL
    DROP TABLE [dbo].[WorkFlowInstance];
GO
IF OBJECT_ID(N'[dbo].[WorkFlowInstanceNode]', 'U') IS NOT NULL
    DROP TABLE [dbo].[WorkFlowInstanceNode];
GO
IF OBJECT_ID(N'[dbo].[WorkFlowTemplateNodeDirector]', 'U') IS NOT NULL
    DROP TABLE [dbo].[WorkFlowTemplateNodeDirector];
GO
IF OBJECT_ID(N'[dbo].[WorkFlowInstanceAction]', 'U') IS NOT NULL
    DROP TABLE [dbo].[WorkFlowInstanceAction];
GO
IF OBJECT_ID(N'[dbo].[UserOrganization]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserOrganization];
GO
IF OBJECT_ID(N'[dbo].[UserPosition]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserPosition];
GO
IF OBJECT_ID(N'[dbo].[UserRole]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserRole];
GO
IF OBJECT_ID(N'[dbo].[PositionRole]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PositionRole];
GO
IF OBJECT_ID(N'[dbo].[RoleResourceEntrySelect]', 'U') IS NOT NULL
    DROP TABLE [dbo].[RoleResourceEntrySelect];
GO
IF OBJECT_ID(N'[dbo].[RoleResourceEntryAlter]', 'U') IS NOT NULL
    DROP TABLE [dbo].[RoleResourceEntryAlter];
GO
IF OBJECT_ID(N'[dbo].[RoleResourceEntryDelete]', 'U') IS NOT NULL
    DROP TABLE [dbo].[RoleResourceEntryDelete];
GO
IF OBJECT_ID(N'[dbo].[RoleResourceEntryAdd]', 'U') IS NOT NULL
    DROP TABLE [dbo].[RoleResourceEntryAdd];
GO
IF OBJECT_ID(N'[dbo].[OrganizationOrganizationType]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OrganizationOrganizationType];
GO
IF OBJECT_ID(N'[dbo].[FeatureEntryL10nLanguage]', 'U') IS NOT NULL
    DROP TABLE [dbo].[FeatureEntryL10nLanguage];
GO
IF OBJECT_ID(N'[dbo].[WorkFlowTemplateNodeRole]', 'U') IS NOT NULL
    DROP TABLE [dbo].[WorkFlowTemplateNodeRole];
GO
IF OBJECT_ID(N'[dbo].[WorkFlowInstanceNodeUser]', 'U') IS NOT NULL
    DROP TABLE [dbo].[WorkFlowInstanceNodeUser];
GO
IF OBJECT_ID(N'[dbo].[WorkFlowInstanceNodeOrganization]', 'U') IS NOT NULL
    DROP TABLE [dbo].[WorkFlowInstanceNodeOrganization];
GO
IF OBJECT_ID(N'[dbo].[WorkFlowInstanceActionUser]', 'U') IS NOT NULL
    DROP TABLE [dbo].[WorkFlowInstanceActionUser];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Organization'
CREATE TABLE [dbo].[Organization] (
    [ID] bigint IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Capacity] bigint  NULL,
    [PersonAmount] bigint  NULL,
    [OrganizationID] bigint  NULL
);
GO

-- Creating table 'User'
CREATE TABLE [dbo].[User] (
    [ID] bigint IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [PasswordDigit] nvarchar(128)  NOT NULL,
    [NickName] nvarchar(50)  NOT NULL,
    [LastLoginTime] datetime  NULL,
    [LanguageID] bigint  NOT NULL
);
GO

-- Creating table 'Role'
CREATE TABLE [dbo].[Role] (
    [ID] bigint IDENTITY(1,1) NOT NULL,
    [RoleTypeID] bigint  NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Remark] nvarchar(max)  NULL,
    [ValidateMethodName] nvarchar(max)  NULL,
    [UserCacheID] bigint  NOT NULL
);
GO

-- Creating table 'Position'
CREATE TABLE [dbo].[Position] (
    [ID] bigint IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Remark] nvarchar(max)  NULL,
    [OrganizationID] bigint  NOT NULL
);
GO

-- Creating table 'FeatureEntry'
CREATE TABLE [dbo].[FeatureEntry] (
    [ID] bigint IDENTITY(1,1) NOT NULL,
    [RoleID] bigint  NOT NULL,
    [FeatureTypeID] bigint  NOT NULL,
    [Target] nvarchar(max)  NOT NULL,
    [FeatureEntryID] bigint  NULL
);
GO

-- Creating table 'ResourceEntry'
CREATE TABLE [dbo].[ResourceEntry] (
    [ID] bigint IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Code] varchar(50)  NOT NULL,
    [CheckTypeID] int  NOT NULL,
    [ResourceTypeName] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'OrganizationType'
CREATE TABLE [dbo].[OrganizationType] (
    [ID] bigint IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [OrganizationTypeID] bigint  NULL
);
GO

-- Creating table 'RoleType'
CREATE TABLE [dbo].[RoleType] (
    [ID] bigint IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'FeatureType'
CREATE TABLE [dbo].[FeatureType] (
    [ID] bigint IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'FeatureEntryL10n'
CREATE TABLE [dbo].[FeatureEntryL10n] (
    [ID] bigint IDENTITY(1,1) NOT NULL,
    [Label] nvarchar(100)  NOT NULL,
    [Hint] nvarchar(max)  NOT NULL,
    [FeatureEntryID] bigint  NOT NULL
);
GO

-- Creating table 'Language'
CREATE TABLE [dbo].[Language] (
    [ID] bigint IDENTITY(1,1) NOT NULL,
    [L10nName] nvarchar(50)  NOT NULL,
    [Name] nvarchar(50)  NULL,
    [ISOCode] varchar(50)  NOT NULL
);
GO

-- Creating table 'LabelL10n'
CREATE TABLE [dbo].[LabelL10n] (
    [ID] bigint IDENTITY(1,1) NOT NULL,
    [LanguageID] bigint  NOT NULL,
    [Code] varchar(50)  NOT NULL,
    [Text] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'WorkFlowTemplateNode'
CREATE TABLE [dbo].[WorkFlowTemplateNode] (
    [ID] bigint IDENTITY(1,1) NOT NULL,
    [WorkFlowTemplateID] bigint  NOT NULL,
    [SinglePersonValidate] bit  NOT NULL,
    [LastStepDirector_ID] bigint  NOT NULL
);
GO

-- Creating table 'WorkFlowTemplate'
CREATE TABLE [dbo].[WorkFlowTemplate] (
    [ID] bigint IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Code] varchar(50)  NOT NULL,
    [LastModifyTime] datetime  NOT NULL
);
GO

-- Creating table 'WorkFlowInstance'
CREATE TABLE [dbo].[WorkFlowInstance] (
    [ID] bigint IDENTITY(1,1) NOT NULL,
    [WorkFlowTemplateID] bigint  NOT NULL,
    [Data] varbinary(max)  NULL
);
GO

-- Creating table 'WorkFlowInstanceNode'
CREATE TABLE [dbo].[WorkFlowInstanceNode] (
    [ID] bigint IDENTITY(1,1) NOT NULL,
    [WorkFlowInstanceID] bigint  NOT NULL,
    [WorkFlowTemplateNodeID] bigint  NOT NULL
);
GO

-- Creating table 'WorkFlowTemplateNodeDirector'
CREATE TABLE [dbo].[WorkFlowTemplateNodeDirector] (
    [ID] bigint IDENTITY(1,1) NOT NULL,
    [WorkFlowTemplateNodeID] bigint  NOT NULL,
    [ActionMethodName] varchar(100)  NULL,
    [DirectionID] int  NOT NULL,
    [ActionTypeID] int  NOT NULL,
    [NextStepProcessorLimitTypeID] int  NOT NULL
);
GO

-- Creating table 'WorkFlowInstanceAction'
CREATE TABLE [dbo].[WorkFlowInstanceAction] (
    [ID] bigint IDENTITY(1,1) NOT NULL,
    [WorkFlowInstanceNodeID] bigint  NOT NULL,
    [WorkFlowTemplateNodeDirectorID] bigint  NOT NULL,
    [CreateTime] datetime  NOT NULL
);
GO

-- Creating table 'UserCache'
CREATE TABLE [dbo].[UserCache] (
    [ID] bigint IDENTITY(1,1) NOT NULL,
    [User_ID] bigint  NOT NULL
);
GO

-- Creating table 'UserOrganization'
CREATE TABLE [dbo].[UserOrganization] (
    [User_ID] bigint  NOT NULL,
    [Organization_ID] bigint  NOT NULL
);
GO

-- Creating table 'UserPosition'
CREATE TABLE [dbo].[UserPosition] (
    [User_ID] bigint  NOT NULL,
    [Position_ID] bigint  NOT NULL
);
GO

-- Creating table 'UserRole'
CREATE TABLE [dbo].[UserRole] (
    [User_ID] bigint  NOT NULL,
    [Role_ID] bigint  NOT NULL
);
GO

-- Creating table 'PositionRole'
CREATE TABLE [dbo].[PositionRole] (
    [Position_ID] bigint  NOT NULL,
    [Role_ID] bigint  NOT NULL
);
GO

-- Creating table 'RoleResourceEntrySelect'
CREATE TABLE [dbo].[RoleResourceEntrySelect] (
    [RoleForSelect_ID] bigint  NOT NULL,
    [SelectableResourceEntry_ID] bigint  NOT NULL
);
GO

-- Creating table 'RoleResourceEntryAlter'
CREATE TABLE [dbo].[RoleResourceEntryAlter] (
    [RoleForAlter_ID] bigint  NOT NULL,
    [AlterableResourceEntry_ID] bigint  NOT NULL
);
GO

-- Creating table 'RoleResourceEntryDelete'
CREATE TABLE [dbo].[RoleResourceEntryDelete] (
    [RoleForDelete_ID] bigint  NOT NULL,
    [DeleteableResourceEntry_ID] bigint  NOT NULL
);
GO

-- Creating table 'RoleResourceEntryAdd'
CREATE TABLE [dbo].[RoleResourceEntryAdd] (
    [RoleForAdd_ID] bigint  NOT NULL,
    [AddableResourceEntry_ID] bigint  NOT NULL
);
GO

-- Creating table 'OrganizationOrganizationType'
CREATE TABLE [dbo].[OrganizationOrganizationType] (
    [Organization_ID] bigint  NOT NULL,
    [OrganizationType_ID] bigint  NOT NULL
);
GO

-- Creating table 'FeatureEntryL10nLanguage'
CREATE TABLE [dbo].[FeatureEntryL10nLanguage] (
    [FeatureEntryL10n_ID] bigint  NOT NULL,
    [Language_ID] bigint  NOT NULL
);
GO

-- Creating table 'WorkFlowTemplateNodeRole'
CREATE TABLE [dbo].[WorkFlowTemplateNodeRole] (
    [WorkFlowTemplateNode_ID] bigint  NOT NULL,
    [Role_ID] bigint  NOT NULL
);
GO

-- Creating table 'WorkFlowInstanceNodeUser'
CREATE TABLE [dbo].[WorkFlowInstanceNodeUser] (
    [WorkFlowInstanceNode_ID] bigint  NOT NULL,
    [User_ID] bigint  NOT NULL
);
GO

-- Creating table 'WorkFlowInstanceNodeOrganization'
CREATE TABLE [dbo].[WorkFlowInstanceNodeOrganization] (
    [WorkFlowInstanceNode_ID] bigint  NOT NULL,
    [Organization_ID] bigint  NOT NULL
);
GO

-- Creating table 'WorkFlowInstanceActionUser'
CREATE TABLE [dbo].[WorkFlowInstanceActionUser] (
    [WorkFlowInstanceAction_ID] bigint  NOT NULL,
    [User_ID] bigint  NOT NULL
);
GO

-- Creating table 'UserCacheRole'
CREATE TABLE [dbo].[UserCacheRole] (
    [UserCache_ID] bigint  NOT NULL,
    [ValidRole_ID] bigint  NOT NULL
);
GO

-- Creating table 'UserCacheFeatureEntry'
CREATE TABLE [dbo].[UserCacheFeatureEntry] (
    [UserCache_ID] bigint  NOT NULL,
    [ValidFeatureEntry_ID] bigint  NOT NULL
);
GO

-- Creating table 'UserCacheResourceEntry'
CREATE TABLE [dbo].[UserCacheResourceEntry] (
    [UserCache_ID] bigint  NOT NULL,
    [ValidResourceEntry_ID] bigint  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ID] in table 'Organization'
ALTER TABLE [dbo].[Organization]
ADD CONSTRAINT [PK_Organization]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'User'
ALTER TABLE [dbo].[User]
ADD CONSTRAINT [PK_User]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Role'
ALTER TABLE [dbo].[Role]
ADD CONSTRAINT [PK_Role]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Position'
ALTER TABLE [dbo].[Position]
ADD CONSTRAINT [PK_Position]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'FeatureEntry'
ALTER TABLE [dbo].[FeatureEntry]
ADD CONSTRAINT [PK_FeatureEntry]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'ResourceEntry'
ALTER TABLE [dbo].[ResourceEntry]
ADD CONSTRAINT [PK_ResourceEntry]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'OrganizationType'
ALTER TABLE [dbo].[OrganizationType]
ADD CONSTRAINT [PK_OrganizationType]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'RoleType'
ALTER TABLE [dbo].[RoleType]
ADD CONSTRAINT [PK_RoleType]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'FeatureType'
ALTER TABLE [dbo].[FeatureType]
ADD CONSTRAINT [PK_FeatureType]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'FeatureEntryL10n'
ALTER TABLE [dbo].[FeatureEntryL10n]
ADD CONSTRAINT [PK_FeatureEntryL10n]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Language'
ALTER TABLE [dbo].[Language]
ADD CONSTRAINT [PK_Language]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'LabelL10n'
ALTER TABLE [dbo].[LabelL10n]
ADD CONSTRAINT [PK_LabelL10n]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'WorkFlowTemplateNode'
ALTER TABLE [dbo].[WorkFlowTemplateNode]
ADD CONSTRAINT [PK_WorkFlowTemplateNode]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'WorkFlowTemplate'
ALTER TABLE [dbo].[WorkFlowTemplate]
ADD CONSTRAINT [PK_WorkFlowTemplate]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'WorkFlowInstance'
ALTER TABLE [dbo].[WorkFlowInstance]
ADD CONSTRAINT [PK_WorkFlowInstance]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'WorkFlowInstanceNode'
ALTER TABLE [dbo].[WorkFlowInstanceNode]
ADD CONSTRAINT [PK_WorkFlowInstanceNode]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'WorkFlowTemplateNodeDirector'
ALTER TABLE [dbo].[WorkFlowTemplateNodeDirector]
ADD CONSTRAINT [PK_WorkFlowTemplateNodeDirector]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'WorkFlowInstanceAction'
ALTER TABLE [dbo].[WorkFlowInstanceAction]
ADD CONSTRAINT [PK_WorkFlowInstanceAction]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'UserCache'
ALTER TABLE [dbo].[UserCache]
ADD CONSTRAINT [PK_UserCache]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [User_ID], [Organization_ID] in table 'UserOrganization'
ALTER TABLE [dbo].[UserOrganization]
ADD CONSTRAINT [PK_UserOrganization]
    PRIMARY KEY NONCLUSTERED ([User_ID], [Organization_ID] ASC);
GO

-- Creating primary key on [User_ID], [Position_ID] in table 'UserPosition'
ALTER TABLE [dbo].[UserPosition]
ADD CONSTRAINT [PK_UserPosition]
    PRIMARY KEY NONCLUSTERED ([User_ID], [Position_ID] ASC);
GO

-- Creating primary key on [User_ID], [Role_ID] in table 'UserRole'
ALTER TABLE [dbo].[UserRole]
ADD CONSTRAINT [PK_UserRole]
    PRIMARY KEY NONCLUSTERED ([User_ID], [Role_ID] ASC);
GO

-- Creating primary key on [Position_ID], [Role_ID] in table 'PositionRole'
ALTER TABLE [dbo].[PositionRole]
ADD CONSTRAINT [PK_PositionRole]
    PRIMARY KEY NONCLUSTERED ([Position_ID], [Role_ID] ASC);
GO

-- Creating primary key on [RoleForSelect_ID], [SelectableResourceEntry_ID] in table 'RoleResourceEntrySelect'
ALTER TABLE [dbo].[RoleResourceEntrySelect]
ADD CONSTRAINT [PK_RoleResourceEntrySelect]
    PRIMARY KEY NONCLUSTERED ([RoleForSelect_ID], [SelectableResourceEntry_ID] ASC);
GO

-- Creating primary key on [RoleForAlter_ID], [AlterableResourceEntry_ID] in table 'RoleResourceEntryAlter'
ALTER TABLE [dbo].[RoleResourceEntryAlter]
ADD CONSTRAINT [PK_RoleResourceEntryAlter]
    PRIMARY KEY NONCLUSTERED ([RoleForAlter_ID], [AlterableResourceEntry_ID] ASC);
GO

-- Creating primary key on [RoleForDelete_ID], [DeleteableResourceEntry_ID] in table 'RoleResourceEntryDelete'
ALTER TABLE [dbo].[RoleResourceEntryDelete]
ADD CONSTRAINT [PK_RoleResourceEntryDelete]
    PRIMARY KEY NONCLUSTERED ([RoleForDelete_ID], [DeleteableResourceEntry_ID] ASC);
GO

-- Creating primary key on [RoleForAdd_ID], [AddableResourceEntry_ID] in table 'RoleResourceEntryAdd'
ALTER TABLE [dbo].[RoleResourceEntryAdd]
ADD CONSTRAINT [PK_RoleResourceEntryAdd]
    PRIMARY KEY NONCLUSTERED ([RoleForAdd_ID], [AddableResourceEntry_ID] ASC);
GO

-- Creating primary key on [Organization_ID], [OrganizationType_ID] in table 'OrganizationOrganizationType'
ALTER TABLE [dbo].[OrganizationOrganizationType]
ADD CONSTRAINT [PK_OrganizationOrganizationType]
    PRIMARY KEY NONCLUSTERED ([Organization_ID], [OrganizationType_ID] ASC);
GO

-- Creating primary key on [FeatureEntryL10n_ID], [Language_ID] in table 'FeatureEntryL10nLanguage'
ALTER TABLE [dbo].[FeatureEntryL10nLanguage]
ADD CONSTRAINT [PK_FeatureEntryL10nLanguage]
    PRIMARY KEY NONCLUSTERED ([FeatureEntryL10n_ID], [Language_ID] ASC);
GO

-- Creating primary key on [WorkFlowTemplateNode_ID], [Role_ID] in table 'WorkFlowTemplateNodeRole'
ALTER TABLE [dbo].[WorkFlowTemplateNodeRole]
ADD CONSTRAINT [PK_WorkFlowTemplateNodeRole]
    PRIMARY KEY NONCLUSTERED ([WorkFlowTemplateNode_ID], [Role_ID] ASC);
GO

-- Creating primary key on [WorkFlowInstanceNode_ID], [User_ID] in table 'WorkFlowInstanceNodeUser'
ALTER TABLE [dbo].[WorkFlowInstanceNodeUser]
ADD CONSTRAINT [PK_WorkFlowInstanceNodeUser]
    PRIMARY KEY NONCLUSTERED ([WorkFlowInstanceNode_ID], [User_ID] ASC);
GO

-- Creating primary key on [WorkFlowInstanceNode_ID], [Organization_ID] in table 'WorkFlowInstanceNodeOrganization'
ALTER TABLE [dbo].[WorkFlowInstanceNodeOrganization]
ADD CONSTRAINT [PK_WorkFlowInstanceNodeOrganization]
    PRIMARY KEY NONCLUSTERED ([WorkFlowInstanceNode_ID], [Organization_ID] ASC);
GO

-- Creating primary key on [WorkFlowInstanceAction_ID], [User_ID] in table 'WorkFlowInstanceActionUser'
ALTER TABLE [dbo].[WorkFlowInstanceActionUser]
ADD CONSTRAINT [PK_WorkFlowInstanceActionUser]
    PRIMARY KEY NONCLUSTERED ([WorkFlowInstanceAction_ID], [User_ID] ASC);
GO

-- Creating primary key on [UserCache_ID], [ValidRole_ID] in table 'UserCacheRole'
ALTER TABLE [dbo].[UserCacheRole]
ADD CONSTRAINT [PK_UserCacheRole]
    PRIMARY KEY NONCLUSTERED ([UserCache_ID], [ValidRole_ID] ASC);
GO

-- Creating primary key on [UserCache_ID], [ValidFeatureEntry_ID] in table 'UserCacheFeatureEntry'
ALTER TABLE [dbo].[UserCacheFeatureEntry]
ADD CONSTRAINT [PK_UserCacheFeatureEntry]
    PRIMARY KEY NONCLUSTERED ([UserCache_ID], [ValidFeatureEntry_ID] ASC);
GO

-- Creating primary key on [UserCache_ID], [ValidResourceEntry_ID] in table 'UserCacheResourceEntry'
ALTER TABLE [dbo].[UserCacheResourceEntry]
ADD CONSTRAINT [PK_UserCacheResourceEntry]
    PRIMARY KEY NONCLUSTERED ([UserCache_ID], [ValidResourceEntry_ID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [User_ID] in table 'UserOrganization'
ALTER TABLE [dbo].[UserOrganization]
ADD CONSTRAINT [FK_UserOrganization_User]
    FOREIGN KEY ([User_ID])
    REFERENCES [dbo].[User]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Organization_ID] in table 'UserOrganization'
ALTER TABLE [dbo].[UserOrganization]
ADD CONSTRAINT [FK_UserOrganization_Organization]
    FOREIGN KEY ([Organization_ID])
    REFERENCES [dbo].[Organization]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserOrganization_Organization'
CREATE INDEX [IX_FK_UserOrganization_Organization]
ON [dbo].[UserOrganization]
    ([Organization_ID]);
GO

-- Creating foreign key on [User_ID] in table 'UserPosition'
ALTER TABLE [dbo].[UserPosition]
ADD CONSTRAINT [FK_UserPosition_User]
    FOREIGN KEY ([User_ID])
    REFERENCES [dbo].[User]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Position_ID] in table 'UserPosition'
ALTER TABLE [dbo].[UserPosition]
ADD CONSTRAINT [FK_UserPosition_Position]
    FOREIGN KEY ([Position_ID])
    REFERENCES [dbo].[Position]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserPosition_Position'
CREATE INDEX [IX_FK_UserPosition_Position]
ON [dbo].[UserPosition]
    ([Position_ID]);
GO

-- Creating foreign key on [User_ID] in table 'UserRole'
ALTER TABLE [dbo].[UserRole]
ADD CONSTRAINT [FK_UserRole_User]
    FOREIGN KEY ([User_ID])
    REFERENCES [dbo].[User]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Role_ID] in table 'UserRole'
ALTER TABLE [dbo].[UserRole]
ADD CONSTRAINT [FK_UserRole_Role]
    FOREIGN KEY ([Role_ID])
    REFERENCES [dbo].[Role]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserRole_Role'
CREATE INDEX [IX_FK_UserRole_Role]
ON [dbo].[UserRole]
    ([Role_ID]);
GO

-- Creating foreign key on [Position_ID] in table 'PositionRole'
ALTER TABLE [dbo].[PositionRole]
ADD CONSTRAINT [FK_PositionRole_Position]
    FOREIGN KEY ([Position_ID])
    REFERENCES [dbo].[Position]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Role_ID] in table 'PositionRole'
ALTER TABLE [dbo].[PositionRole]
ADD CONSTRAINT [FK_PositionRole_Role]
    FOREIGN KEY ([Role_ID])
    REFERENCES [dbo].[Role]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PositionRole_Role'
CREATE INDEX [IX_FK_PositionRole_Role]
ON [dbo].[PositionRole]
    ([Role_ID]);
GO

-- Creating foreign key on [RoleID] in table 'FeatureEntry'
ALTER TABLE [dbo].[FeatureEntry]
ADD CONSTRAINT [FK_RoleFeatureEntry]
    FOREIGN KEY ([RoleID])
    REFERENCES [dbo].[Role]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_RoleFeatureEntry'
CREATE INDEX [IX_FK_RoleFeatureEntry]
ON [dbo].[FeatureEntry]
    ([RoleID]);
GO

-- Creating foreign key on [RoleForSelect_ID] in table 'RoleResourceEntrySelect'
ALTER TABLE [dbo].[RoleResourceEntrySelect]
ADD CONSTRAINT [FK_RoleResourceEntrySelect_Role]
    FOREIGN KEY ([RoleForSelect_ID])
    REFERENCES [dbo].[Role]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [SelectableResourceEntry_ID] in table 'RoleResourceEntrySelect'
ALTER TABLE [dbo].[RoleResourceEntrySelect]
ADD CONSTRAINT [FK_RoleResourceEntrySelect_ResourceEntry]
    FOREIGN KEY ([SelectableResourceEntry_ID])
    REFERENCES [dbo].[ResourceEntry]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_RoleResourceEntrySelect_ResourceEntry'
CREATE INDEX [IX_FK_RoleResourceEntrySelect_ResourceEntry]
ON [dbo].[RoleResourceEntrySelect]
    ([SelectableResourceEntry_ID]);
GO

-- Creating foreign key on [RoleForAlter_ID] in table 'RoleResourceEntryAlter'
ALTER TABLE [dbo].[RoleResourceEntryAlter]
ADD CONSTRAINT [FK_RoleResourceEntryAlter_Role]
    FOREIGN KEY ([RoleForAlter_ID])
    REFERENCES [dbo].[Role]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [AlterableResourceEntry_ID] in table 'RoleResourceEntryAlter'
ALTER TABLE [dbo].[RoleResourceEntryAlter]
ADD CONSTRAINT [FK_RoleResourceEntryAlter_ResourceEntry]
    FOREIGN KEY ([AlterableResourceEntry_ID])
    REFERENCES [dbo].[ResourceEntry]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_RoleResourceEntryAlter_ResourceEntry'
CREATE INDEX [IX_FK_RoleResourceEntryAlter_ResourceEntry]
ON [dbo].[RoleResourceEntryAlter]
    ([AlterableResourceEntry_ID]);
GO

-- Creating foreign key on [RoleForDelete_ID] in table 'RoleResourceEntryDelete'
ALTER TABLE [dbo].[RoleResourceEntryDelete]
ADD CONSTRAINT [FK_RoleResourceEntryDelete_Role]
    FOREIGN KEY ([RoleForDelete_ID])
    REFERENCES [dbo].[Role]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [DeleteableResourceEntry_ID] in table 'RoleResourceEntryDelete'
ALTER TABLE [dbo].[RoleResourceEntryDelete]
ADD CONSTRAINT [FK_RoleResourceEntryDelete_ResourceEntry]
    FOREIGN KEY ([DeleteableResourceEntry_ID])
    REFERENCES [dbo].[ResourceEntry]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_RoleResourceEntryDelete_ResourceEntry'
CREATE INDEX [IX_FK_RoleResourceEntryDelete_ResourceEntry]
ON [dbo].[RoleResourceEntryDelete]
    ([DeleteableResourceEntry_ID]);
GO

-- Creating foreign key on [RoleForAdd_ID] in table 'RoleResourceEntryAdd'
ALTER TABLE [dbo].[RoleResourceEntryAdd]
ADD CONSTRAINT [FK_RoleResourceEntryAdd_Role]
    FOREIGN KEY ([RoleForAdd_ID])
    REFERENCES [dbo].[Role]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [AddableResourceEntry_ID] in table 'RoleResourceEntryAdd'
ALTER TABLE [dbo].[RoleResourceEntryAdd]
ADD CONSTRAINT [FK_RoleResourceEntryAdd_ResourceEntry]
    FOREIGN KEY ([AddableResourceEntry_ID])
    REFERENCES [dbo].[ResourceEntry]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_RoleResourceEntryAdd_ResourceEntry'
CREATE INDEX [IX_FK_RoleResourceEntryAdd_ResourceEntry]
ON [dbo].[RoleResourceEntryAdd]
    ([AddableResourceEntry_ID]);
GO

-- Creating foreign key on [Organization_ID] in table 'OrganizationOrganizationType'
ALTER TABLE [dbo].[OrganizationOrganizationType]
ADD CONSTRAINT [FK_OrganizationOrganizationType_Organization]
    FOREIGN KEY ([Organization_ID])
    REFERENCES [dbo].[Organization]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [OrganizationType_ID] in table 'OrganizationOrganizationType'
ALTER TABLE [dbo].[OrganizationOrganizationType]
ADD CONSTRAINT [FK_OrganizationOrganizationType_OrganizationType]
    FOREIGN KEY ([OrganizationType_ID])
    REFERENCES [dbo].[OrganizationType]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrganizationOrganizationType_OrganizationType'
CREATE INDEX [IX_FK_OrganizationOrganizationType_OrganizationType]
ON [dbo].[OrganizationOrganizationType]
    ([OrganizationType_ID]);
GO

-- Creating foreign key on [RoleTypeID] in table 'Role'
ALTER TABLE [dbo].[Role]
ADD CONSTRAINT [FK_RoleRoleType]
    FOREIGN KEY ([RoleTypeID])
    REFERENCES [dbo].[RoleType]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_RoleRoleType'
CREATE INDEX [IX_FK_RoleRoleType]
ON [dbo].[Role]
    ([RoleTypeID]);
GO

-- Creating foreign key on [FeatureTypeID] in table 'FeatureEntry'
ALTER TABLE [dbo].[FeatureEntry]
ADD CONSTRAINT [FK_FeatureEntryFeatureType]
    FOREIGN KEY ([FeatureTypeID])
    REFERENCES [dbo].[FeatureType]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_FeatureEntryFeatureType'
CREATE INDEX [IX_FK_FeatureEntryFeatureType]
ON [dbo].[FeatureEntry]
    ([FeatureTypeID]);
GO

-- Creating foreign key on [FeatureEntryL10n_ID] in table 'FeatureEntryL10nLanguage'
ALTER TABLE [dbo].[FeatureEntryL10nLanguage]
ADD CONSTRAINT [FK_FeatureEntryL10nLanguage_FeatureEntryL10n]
    FOREIGN KEY ([FeatureEntryL10n_ID])
    REFERENCES [dbo].[FeatureEntryL10n]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Language_ID] in table 'FeatureEntryL10nLanguage'
ALTER TABLE [dbo].[FeatureEntryL10nLanguage]
ADD CONSTRAINT [FK_FeatureEntryL10nLanguage_Language]
    FOREIGN KEY ([Language_ID])
    REFERENCES [dbo].[Language]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_FeatureEntryL10nLanguage_Language'
CREATE INDEX [IX_FK_FeatureEntryL10nLanguage_Language]
ON [dbo].[FeatureEntryL10nLanguage]
    ([Language_ID]);
GO

-- Creating foreign key on [FeatureEntryID] in table 'FeatureEntryL10n'
ALTER TABLE [dbo].[FeatureEntryL10n]
ADD CONSTRAINT [FK_FeatureEntryFeatureEntryL10n]
    FOREIGN KEY ([FeatureEntryID])
    REFERENCES [dbo].[FeatureEntry]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_FeatureEntryFeatureEntryL10n'
CREATE INDEX [IX_FK_FeatureEntryFeatureEntryL10n]
ON [dbo].[FeatureEntryL10n]
    ([FeatureEntryID]);
GO

-- Creating foreign key on [LanguageID] in table 'User'
ALTER TABLE [dbo].[User]
ADD CONSTRAINT [FK_UserLanguage]
    FOREIGN KEY ([LanguageID])
    REFERENCES [dbo].[Language]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserLanguage'
CREATE INDEX [IX_FK_UserLanguage]
ON [dbo].[User]
    ([LanguageID]);
GO

-- Creating foreign key on [OrganizationID] in table 'Organization'
ALTER TABLE [dbo].[Organization]
ADD CONSTRAINT [FK_OrganizationTree]
    FOREIGN KEY ([OrganizationID])
    REFERENCES [dbo].[Organization]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrganizationTree'
CREATE INDEX [IX_FK_OrganizationTree]
ON [dbo].[Organization]
    ([OrganizationID]);
GO

-- Creating foreign key on [FeatureEntryID] in table 'FeatureEntry'
ALTER TABLE [dbo].[FeatureEntry]
ADD CONSTRAINT [FK_FeatureEntryTree]
    FOREIGN KEY ([FeatureEntryID])
    REFERENCES [dbo].[FeatureEntry]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_FeatureEntryTree'
CREATE INDEX [IX_FK_FeatureEntryTree]
ON [dbo].[FeatureEntry]
    ([FeatureEntryID]);
GO

-- Creating foreign key on [OrganizationID] in table 'Position'
ALTER TABLE [dbo].[Position]
ADD CONSTRAINT [FK_PositionOrganization]
    FOREIGN KEY ([OrganizationID])
    REFERENCES [dbo].[Organization]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PositionOrganization'
CREATE INDEX [IX_FK_PositionOrganization]
ON [dbo].[Position]
    ([OrganizationID]);
GO

-- Creating foreign key on [OrganizationTypeID] in table 'OrganizationType'
ALTER TABLE [dbo].[OrganizationType]
ADD CONSTRAINT [FK_OrganizationTypeTree]
    FOREIGN KEY ([OrganizationTypeID])
    REFERENCES [dbo].[OrganizationType]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrganizationTypeTree'
CREATE INDEX [IX_FK_OrganizationTypeTree]
ON [dbo].[OrganizationType]
    ([OrganizationTypeID]);
GO

-- Creating foreign key on [LanguageID] in table 'LabelL10n'
ALTER TABLE [dbo].[LabelL10n]
ADD CONSTRAINT [FK_LabelL10nLanguage]
    FOREIGN KEY ([LanguageID])
    REFERENCES [dbo].[Language]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_LabelL10nLanguage'
CREATE INDEX [IX_FK_LabelL10nLanguage]
ON [dbo].[LabelL10n]
    ([LanguageID]);
GO

-- Creating foreign key on [WorkFlowInstanceID] in table 'WorkFlowInstanceNode'
ALTER TABLE [dbo].[WorkFlowInstanceNode]
ADD CONSTRAINT [FK_WorkFlowInstanceWorkFlowInstanceNode]
    FOREIGN KEY ([WorkFlowInstanceID])
    REFERENCES [dbo].[WorkFlowInstance]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_WorkFlowInstanceWorkFlowInstanceNode'
CREATE INDEX [IX_FK_WorkFlowInstanceWorkFlowInstanceNode]
ON [dbo].[WorkFlowInstanceNode]
    ([WorkFlowInstanceID]);
GO

-- Creating foreign key on [WorkFlowTemplateNodeID] in table 'WorkFlowInstanceNode'
ALTER TABLE [dbo].[WorkFlowInstanceNode]
ADD CONSTRAINT [FK_WorkFlowTemplateNodeWorkFlowInstanceNode]
    FOREIGN KEY ([WorkFlowTemplateNodeID])
    REFERENCES [dbo].[WorkFlowTemplateNode]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_WorkFlowTemplateNodeWorkFlowInstanceNode'
CREATE INDEX [IX_FK_WorkFlowTemplateNodeWorkFlowInstanceNode]
ON [dbo].[WorkFlowInstanceNode]
    ([WorkFlowTemplateNodeID]);
GO

-- Creating foreign key on [WorkFlowTemplateID] in table 'WorkFlowTemplateNode'
ALTER TABLE [dbo].[WorkFlowTemplateNode]
ADD CONSTRAINT [FK_WorkFlowTemplateWorkFlowTemplateNode]
    FOREIGN KEY ([WorkFlowTemplateID])
    REFERENCES [dbo].[WorkFlowTemplate]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_WorkFlowTemplateWorkFlowTemplateNode'
CREATE INDEX [IX_FK_WorkFlowTemplateWorkFlowTemplateNode]
ON [dbo].[WorkFlowTemplateNode]
    ([WorkFlowTemplateID]);
GO

-- Creating foreign key on [WorkFlowTemplateID] in table 'WorkFlowInstance'
ALTER TABLE [dbo].[WorkFlowInstance]
ADD CONSTRAINT [FK_WorkFlowTemplateWorkFlowInstance]
    FOREIGN KEY ([WorkFlowTemplateID])
    REFERENCES [dbo].[WorkFlowTemplate]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_WorkFlowTemplateWorkFlowInstance'
CREATE INDEX [IX_FK_WorkFlowTemplateWorkFlowInstance]
ON [dbo].[WorkFlowInstance]
    ([WorkFlowTemplateID]);
GO

-- Creating foreign key on [WorkFlowTemplateNodeID] in table 'WorkFlowTemplateNodeDirector'
ALTER TABLE [dbo].[WorkFlowTemplateNodeDirector]
ADD CONSTRAINT [FK_WorkFlowTemplateNodeWorkFlowTemplateNodeDirector]
    FOREIGN KEY ([WorkFlowTemplateNodeID])
    REFERENCES [dbo].[WorkFlowTemplateNode]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_WorkFlowTemplateNodeWorkFlowTemplateNodeDirector'
CREATE INDEX [IX_FK_WorkFlowTemplateNodeWorkFlowTemplateNodeDirector]
ON [dbo].[WorkFlowTemplateNodeDirector]
    ([WorkFlowTemplateNodeID]);
GO

-- Creating foreign key on [LastStepDirector_ID] in table 'WorkFlowTemplateNode'
ALTER TABLE [dbo].[WorkFlowTemplateNode]
ADD CONSTRAINT [FK_WorkFlowTemplateNodeWorkFlowTemplateNodeDirector1]
    FOREIGN KEY ([LastStepDirector_ID])
    REFERENCES [dbo].[WorkFlowTemplateNodeDirector]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_WorkFlowTemplateNodeWorkFlowTemplateNodeDirector1'
CREATE INDEX [IX_FK_WorkFlowTemplateNodeWorkFlowTemplateNodeDirector1]
ON [dbo].[WorkFlowTemplateNode]
    ([LastStepDirector_ID]);
GO

-- Creating foreign key on [WorkFlowTemplateNode_ID] in table 'WorkFlowTemplateNodeRole'
ALTER TABLE [dbo].[WorkFlowTemplateNodeRole]
ADD CONSTRAINT [FK_WorkFlowTemplateNodeRole_WorkFlowTemplateNode]
    FOREIGN KEY ([WorkFlowTemplateNode_ID])
    REFERENCES [dbo].[WorkFlowTemplateNode]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Role_ID] in table 'WorkFlowTemplateNodeRole'
ALTER TABLE [dbo].[WorkFlowTemplateNodeRole]
ADD CONSTRAINT [FK_WorkFlowTemplateNodeRole_Role]
    FOREIGN KEY ([Role_ID])
    REFERENCES [dbo].[Role]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_WorkFlowTemplateNodeRole_Role'
CREATE INDEX [IX_FK_WorkFlowTemplateNodeRole_Role]
ON [dbo].[WorkFlowTemplateNodeRole]
    ([Role_ID]);
GO

-- Creating foreign key on [WorkFlowInstanceNode_ID] in table 'WorkFlowInstanceNodeUser'
ALTER TABLE [dbo].[WorkFlowInstanceNodeUser]
ADD CONSTRAINT [FK_WorkFlowInstanceNodeUser_WorkFlowInstanceNode]
    FOREIGN KEY ([WorkFlowInstanceNode_ID])
    REFERENCES [dbo].[WorkFlowInstanceNode]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [User_ID] in table 'WorkFlowInstanceNodeUser'
ALTER TABLE [dbo].[WorkFlowInstanceNodeUser]
ADD CONSTRAINT [FK_WorkFlowInstanceNodeUser_User]
    FOREIGN KEY ([User_ID])
    REFERENCES [dbo].[User]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_WorkFlowInstanceNodeUser_User'
CREATE INDEX [IX_FK_WorkFlowInstanceNodeUser_User]
ON [dbo].[WorkFlowInstanceNodeUser]
    ([User_ID]);
GO

-- Creating foreign key on [WorkFlowInstanceNode_ID] in table 'WorkFlowInstanceNodeOrganization'
ALTER TABLE [dbo].[WorkFlowInstanceNodeOrganization]
ADD CONSTRAINT [FK_WorkFlowInstanceNodeOrganization_WorkFlowInstanceNode]
    FOREIGN KEY ([WorkFlowInstanceNode_ID])
    REFERENCES [dbo].[WorkFlowInstanceNode]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Organization_ID] in table 'WorkFlowInstanceNodeOrganization'
ALTER TABLE [dbo].[WorkFlowInstanceNodeOrganization]
ADD CONSTRAINT [FK_WorkFlowInstanceNodeOrganization_Organization]
    FOREIGN KEY ([Organization_ID])
    REFERENCES [dbo].[Organization]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_WorkFlowInstanceNodeOrganization_Organization'
CREATE INDEX [IX_FK_WorkFlowInstanceNodeOrganization_Organization]
ON [dbo].[WorkFlowInstanceNodeOrganization]
    ([Organization_ID]);
GO

-- Creating foreign key on [WorkFlowInstanceNodeID] in table 'WorkFlowInstanceAction'
ALTER TABLE [dbo].[WorkFlowInstanceAction]
ADD CONSTRAINT [FK_WorkFlowInstanceActionWorkFlowInstanceNode]
    FOREIGN KEY ([WorkFlowInstanceNodeID])
    REFERENCES [dbo].[WorkFlowInstanceNode]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_WorkFlowInstanceActionWorkFlowInstanceNode'
CREATE INDEX [IX_FK_WorkFlowInstanceActionWorkFlowInstanceNode]
ON [dbo].[WorkFlowInstanceAction]
    ([WorkFlowInstanceNodeID]);
GO

-- Creating foreign key on [WorkFlowInstanceAction_ID] in table 'WorkFlowInstanceActionUser'
ALTER TABLE [dbo].[WorkFlowInstanceActionUser]
ADD CONSTRAINT [FK_WorkFlowInstanceActionUser_WorkFlowInstanceAction]
    FOREIGN KEY ([WorkFlowInstanceAction_ID])
    REFERENCES [dbo].[WorkFlowInstanceAction]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [User_ID] in table 'WorkFlowInstanceActionUser'
ALTER TABLE [dbo].[WorkFlowInstanceActionUser]
ADD CONSTRAINT [FK_WorkFlowInstanceActionUser_User]
    FOREIGN KEY ([User_ID])
    REFERENCES [dbo].[User]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_WorkFlowInstanceActionUser_User'
CREATE INDEX [IX_FK_WorkFlowInstanceActionUser_User]
ON [dbo].[WorkFlowInstanceActionUser]
    ([User_ID]);
GO

-- Creating foreign key on [WorkFlowTemplateNodeDirectorID] in table 'WorkFlowInstanceAction'
ALTER TABLE [dbo].[WorkFlowInstanceAction]
ADD CONSTRAINT [FK_WorkFlowInstanceActionWorkFlowTemplateNodeDirector]
    FOREIGN KEY ([WorkFlowTemplateNodeDirectorID])
    REFERENCES [dbo].[WorkFlowTemplateNodeDirector]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_WorkFlowInstanceActionWorkFlowTemplateNodeDirector'
CREATE INDEX [IX_FK_WorkFlowInstanceActionWorkFlowTemplateNodeDirector]
ON [dbo].[WorkFlowInstanceAction]
    ([WorkFlowTemplateNodeDirectorID]);
GO

-- Creating foreign key on [User_ID] in table 'UserCache'
ALTER TABLE [dbo].[UserCache]
ADD CONSTRAINT [FK_UserUserCache]
    FOREIGN KEY ([User_ID])
    REFERENCES [dbo].[User]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserUserCache'
CREATE INDEX [IX_FK_UserUserCache]
ON [dbo].[UserCache]
    ([User_ID]);
GO

-- Creating foreign key on [UserCache_ID] in table 'UserCacheRole'
ALTER TABLE [dbo].[UserCacheRole]
ADD CONSTRAINT [FK_UserCacheRole_UserCache]
    FOREIGN KEY ([UserCache_ID])
    REFERENCES [dbo].[UserCache]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [ValidRole_ID] in table 'UserCacheRole'
ALTER TABLE [dbo].[UserCacheRole]
ADD CONSTRAINT [FK_UserCacheRole_Role]
    FOREIGN KEY ([ValidRole_ID])
    REFERENCES [dbo].[Role]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserCacheRole_Role'
CREATE INDEX [IX_FK_UserCacheRole_Role]
ON [dbo].[UserCacheRole]
    ([ValidRole_ID]);
GO

-- Creating foreign key on [UserCache_ID] in table 'UserCacheFeatureEntry'
ALTER TABLE [dbo].[UserCacheFeatureEntry]
ADD CONSTRAINT [FK_UserCacheFeatureEntry_UserCache]
    FOREIGN KEY ([UserCache_ID])
    REFERENCES [dbo].[UserCache]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [ValidFeatureEntry_ID] in table 'UserCacheFeatureEntry'
ALTER TABLE [dbo].[UserCacheFeatureEntry]
ADD CONSTRAINT [FK_UserCacheFeatureEntry_FeatureEntry]
    FOREIGN KEY ([ValidFeatureEntry_ID])
    REFERENCES [dbo].[FeatureEntry]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserCacheFeatureEntry_FeatureEntry'
CREATE INDEX [IX_FK_UserCacheFeatureEntry_FeatureEntry]
ON [dbo].[UserCacheFeatureEntry]
    ([ValidFeatureEntry_ID]);
GO

-- Creating foreign key on [UserCache_ID] in table 'UserCacheResourceEntry'
ALTER TABLE [dbo].[UserCacheResourceEntry]
ADD CONSTRAINT [FK_UserCacheResourceEntry_UserCache]
    FOREIGN KEY ([UserCache_ID])
    REFERENCES [dbo].[UserCache]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [ValidResourceEntry_ID] in table 'UserCacheResourceEntry'
ALTER TABLE [dbo].[UserCacheResourceEntry]
ADD CONSTRAINT [FK_UserCacheResourceEntry_ResourceEntry]
    FOREIGN KEY ([ValidResourceEntry_ID])
    REFERENCES [dbo].[ResourceEntry]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserCacheResourceEntry_ResourceEntry'
CREATE INDEX [IX_FK_UserCacheResourceEntry_ResourceEntry]
ON [dbo].[UserCacheResourceEntry]
    ([ValidResourceEntry_ID]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------